package com.coolyu.lab.server;

import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStreamWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.*;

/**
 * Servlet implementation class YtDownloader
 */
public class Manifest extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public Manifest() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		String version = "version " + request.getParameter("version");
		
		JSONObject json = new JSONObject();
		JSONArray jsonArray = new JSONArray();
		JSONObject entriesObj = new JSONObject();
		
		try {
			//json
			json.put("betaManifestVersion", 1);
			json.put("version", version);
			//entriesObj
			jsonArray.put(new JSONObject().put("url", "CoolyuYtPlayerEnhanced.jsp"));
			jsonArray.put(new JSONObject().put("url", "../JavascriptSrc/CoolyuYtPlayerEnhanced.js"));
			jsonArray.put(new JSONObject().put("url", "../JavascriptSrc/Offline.js"));
			jsonArray.put(new JSONObject().put("url", "../JavascriptSrc/sample.js"));
			jsonArray.put(new JSONObject().put("url", "../JavascriptSrc/gears_init.js"));
			jsonArray.put(new JSONObject().put("url", "../JavascriptSrc/jquery.js"));
			jsonArray.put(new JSONObject().put("url", "../JavascriptSrc/swfobject.js"));
			jsonArray.put(new JSONObject().put("url", "../player-viral.swf"));
			jsonArray.put(new JSONObject().put("url", "../preview.jpg"));
			jsonArray.put(new JSONObject().put("url", "../video.flv"));
			jsonArray.put(new JSONObject().put("url", "../youtube.png"));
			
			//jsonArray.put(entriesObj);
			//
			json.put("entries", jsonArray);
			
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.getOutputStream().println(json.toString());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
